#ifndef SOCKETHELPER_H
#define SOCKETHELPER_H

#include <QObject>
#include <QTcpSocket>
#include "messagepackage.h"

class socketHelper : public QObject
{
    Q_OBJECT
public:
    static socketHelper *getInstance();
    static void removeInstance();
    QTcpSocket* getSocket();
    void setCurrentUser(const QString &username);
    //会议
    void createMeeting();
    void joinMeeting(QString id);

private:
    explicit socketHelper(QObject *parent = nullptr);
    ~socketHelper();
    static socketHelper* instance;
    void registHanler(MessagePackage& pack);
    void loginHanler(MessagePackage& pack);
    QString m_currentUser;

    QTcpSocket* socket;
private slots:
    void onReadyRead();
signals:
    //文件相关
    void fileListReceived(QJsonArray files);
    void fileDataReceived(QString filename,QByteArray data);
    void fileUploadSuccess();

    void registSuccess();
    void registFailed();
    void loginSuccess(QString name);
    void loginFailed();
    void add_onl(QString name);
    void recv_singleMessage(MessagePackage& pack);

    //讨论组相关
    void groupCreated(bool success, const QString &groupId, const QString &groupName);
    void groupListReceived(const QJsonArray &groups);
    void groupMessageReceived(MessagePackage &pack);
    void groupMemberAdded(const QString &groupId, const QString &username);
    void groupJoined(bool success, const QString &groupId, const QString &groupName);

    //视频
    void meetingCreated(MessagePackage ipport_pack);
    void meetingJoined(MessagePackage pack);
};

#endif // SOCKETHELPER_H
